import { Injectable } from '@angular/core';
import { BaseService } from '@core/routes-services/base.service';
import { CacheService } from '@core/routes-services/cache.service';
import { HttpClient } from '@angular/common/http';
import { myValidNull } from '@core/util/string-utils';

/**
 * otc 运营中心 服务
 */
@Injectable()
export class RuleTemplateService extends BaseService {

  constructor(http: HttpClient, cacheService: CacheService) {
    super(http, cacheService);
  }

  base_url: any = 'api/otcCreditRuleTemplate';


  /**
   * 分页
   *
   * @param user
   * @returns {Promise<any>}
   */
  pagination(page: any,  type: any, keyword: any): Promise<any> {
    const url = this.base_url + '/pagination';
    if (keyword) {
      page['_filter_like_title'] = keyword;
    }
    if (type) {
      page['_filter_eq_type'] = type;
    }
    return this.post(url, page);
  }


  /**
   * 修改
   *
   * @param id
   * @param entity
   * @returns {Promise<any>}
   */
  saveOrUpdateEntity(code: any, entity: any): Promise<any> {
    if (code) {
      const url = this.base_url + '/' + code;
      return this.put(url, entity);
    } else {
      const url = this.base_url;
      return this.post(url, entity);
    }
  }

  /**
   * 获取查看详情
   *
   * @param id
   * @returns {Promise<any>}
   */
  detail(code: any): Promise<any> {
    const url = this.base_url + '/' + code;
    return this.get(url);
  }

  /**
   * 删除
   *
   * @param ids
   * @returns {Promise<any>}
   */
  deleteEntity(code): Promise<any> {
    const url = this.base_url+ '/';
    return this.delete(url, code);
  }

  /**
   * 获取全部
   *
   * @returns {Promise<any>}
   */
  getAll(): Promise<any> {
    const url = this.base_url + '/all';
    return this.get(url);
  }
}
